package br.unifor.cct.mia.runner;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import weka.classifiers.trees.J48;
import weka.gui.explorer.ClassifierPanel;
import br.unifor.cct.mia.dataenhancement.Database;
import br.unifor.cct.mia.dataenhancement.Structure;
import br.unifor.cct.mia.dataenhancement.Tuple;
import br.unifor.cct.mia.ga.GaDE;
import br.unifor.cct.mia.util.LoadFile;

public class MissingValue {
	
	public static String DATASET_STRUCTURE = "./data/zooMV_estrutura.txt";
	public static String DATASET_DATA = "./dataPart/zooMV_TRAIN_data.txt";
	public static ClassifierPanel sp = new ClassifierPanel();
	public static Tuple tuples;
	
	public static void main(String[] a) {
    	Structure st = LoadFile.loadStructure(DATASET_STRUCTURE);
    	Database db = LoadFile.loadDatabase(DATASET_DATA);
    	System.out.println("Arquivos carregados com sucesso");
    	
    	//percentual total de valores faltantes
    	/*int total = (int)Math.round(db.size()*st.size()*0.10);
    	
    	System.out.println("Total = "+total);
    	List aux = LoadFile.generateFaultDatabase(db.size(), st.size(), total);
    	
    	aux = orderPositions(aux, db.size(), st.size());*/
    	
    	List positions = LoadFile.getFaultDatabase(st,db);
    	tuples = new Tuple();
    	db.mountStr(tuples, positions);
    	
    	sp.m_ClassifierEditor.setValue(new J48());
    	
        try {
            Thread t = new Thread(new GaDE(st, db, positions, positions.size(), tuples,null));
            t.start();
        	t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
	
	public static List orderPositions(List positions, int tamSize, int tamCol) {
		List pointList = new ArrayList();
		int index = -1;
		
		for (int i = 0; i < tamSize; i++) {
			for (int j = 0; j < tamCol; j++) {
				index = positions.indexOf(new Point(i, j));
				if (index > -1) pointList.add(positions.get(index));
			}
		}
		
		return pointList;
	}
}
